<?php
/**
 * Created by PhpStorm.
 * User: jungshen
 * Date: 2018/8/2
 * Time: 14:45
 */

namespace app\api\controller\other;

use app\api\controller\BasicApi;
use Db;
use think\facade\Request;


class Dynamic extends BasicApi
{
    /**
     * @Notes: 所有动态列表
     * @return \think\response\Json
     * @author: Forska
     * @email: 736523388@qq.com
     * @DateTime: 2018/10/24 16:34
     */
    public function alllists(){
        $page = Request::param('page',1);
        $pagesize = Request::param('pagesize',10);
        $province=input('province');
        $db = Db::table('dynamic')->where('status',1);
        if($province){
            $db->where('province',$province);
        }
        $list=$db->page($page,$pagesize)->order('create_at desc')->select();
        foreach ($list as &$item) {
            $item['images'] = explode('|',$item['images']);
            $item['create_at'] = date('Y-m-d',$item['create_at']);
            $item['praised'] = Db::name('praise')->where('attach_id',$item['id'])->where('type',2)->count();
            $item['member_info']=Db::name('store_member')->where('id',$item['mid'])->field('nickname,headimg,type,phone')->find();
        }
        return json(['msg'=>'success','data'=>$list],200);
    }
    public function detail(){
        $id = input('id/d');
        $map = [
            'id'=>array('eq',$id)
        ];
        $info = Db::table('dynamic')->where($map)->find();
        if(empty($info) || $info['status'] != 1){
            return json(['msg'=>'找不到'],404);
        }
        Db::table('dynamic')->where($map)->setInc('borwse',1);
        $info['create_at'] = date('Y-m-d',$info['create_at']);
        $info['images'] = explode('|',$info['images']);
        $info['member_info']=Db::name('store_member')->where('id',$info['mid'])->field('nickname,headimg,type')->find();
        return json(['msg'=>'success','data'=>$info],200);
    }
}